import requests
from bs4 import BeautifulSoup

# 定义请求的URL
url = "https://www.maoyan.com/cinemas"
cityId=50
# 定义请求的参数
params = {
    'brandId': -1,
    'districtId': -1,
    'hallType': -1,
    'serviceId': -1,
    'movieId': 1446323,
    'showDate': '2024-05-08'
}

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Encoding': 'gzip, deflate, br, zstd',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'Cookie': f'__mta=219076518.1714556028439.1714557316064.1714558014685.20; uuid_n_v=v1; uuid=E8F169D0079D11EF9F28D3BFFA06DA4913D0711C4AD14851AF91ED67A5B4570E; b-user-id=7faaae72-d90e-16a8-68da-41b717202699; _lxsdk_cuid=18f3380c4b1c8-07fe7e69767034-26001d51-13c680-18f3380c4b1c8; _lxsdk=E8F169D0079D11EF9F28D3BFFA06DA4913D0711C4AD14851AF91ED67A5B4570E; _csrf=6c1da934867c2c2bd554e3ac8ee5e0479bbb1d78b6e87929cd4ffe8ecb1e383d; _lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; Hm_lvt_703e94591e87be68cc8da0da7cbd0be2=1714556028,1714788877; Hm_lpvt_703e94591e87be68cc8da0da7cbd0be2=1714788882; __mta=219076518.1714556028439.1714558014685.1714788882251.21; _lxsdk_s=18f4161c443-b23-ec3-4e6%7C%7C4; ci={cityId}',
    'Host': 'www.maoyan.com',
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"'
}

response = requests.get(url, params=params, headers=headers)

print(response.text)
# 检查响应状态码
if response.status_code == 200:
    # 使用BeautifulSoup解析HTML内容
    soup = BeautifulSoup(response.text, 'html.parser')

    # 找到包含影院信息的元素
    cinemas = soup.find_all('div', class_='cinema-cell')

    # 遍历所有影院元素，提取并格式化信息
    for cinema in cinemas:
        # 获取影院名称
        cinema_name = cinema.find('div', class_='cinema-info').find('a').text
        # 获取影院地址
        cinema_address = cinema.find('p', class_='cinema-address').text
        # 打印影院信息
        print(f'影院名称: {cinema_name}\n{cinema_address}\n')
else:
    print("请求失败，状态码：", response.status_code)
